package com.qianfeng.smartmetting.controller;

import com.qianfeng.smartmetting.entity.TimeSlot;
import com.qianfeng.smartmetting.service.TimeSlotService;
import com.qianfeng.smartmetting.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/timeslot")
public class TimeSlotController {

    @Autowired
    private TimeSlotService timeSlotService;

    //通过会议室id 查看会议室的预约情况
    @GetMapping("/list")
    public Map list(int page,int limit,Integer roomid){
        try{

            List<TimeSlot> list = timeSlotService.findByRoomId(roomid,(page-1)*limit,limit);
            return CommonResult.ok("查询成功",list);
        }catch (Exception e){
            return CommonResult.error("发生异常");
        }
    }

    //修改预约时间
    @PutMapping("/modify")
    public Map modify(TimeSlot timeSlot){
        try{
            boolean flag = timeSlotService.updateById(timeSlot);
            return CommonResult.ok(flag?"修改成功":"修改失败",null);
        }catch (Exception e){
            return CommonResult.error("发生异常");
        }
    }
}
